package com.tiantianfresh.model.dao;

import com.tiantianfresh.model.pojo.Address;
import com.tiantianfresh.model.pojo.Order;
import com.tiantianfresh.model.pojo.OrderAddress;
import com.tiantianfresh.model.pojo.OrderState;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

/**
 * @author FANGAO
 * @date 2021/12/5 - 下午 20:43
 */
public interface OrderMapper extends Mapper<Order> {
    /**
     * 添加订单
     * @param order
     * @return
     */
    @Insert("INSERT INTO r_order(orderid,orderdate,totalPrice,userid,orderState,addressId) VALUE (#{orderid},#{orderdate},#{totalPrice},#{userid},#{orderState},#{addressId})")
    int addOrder(Order order);
    ///**
    // * 订单数量
    // * @param order
    // * @return
    // */
    //@Select("select count(*) from r_order where orderid = #{orderid}")
    //int queryOrderCount(Order order);
    ///**
    // * 防止出现重复订单
    // * @param order
    // * @return
    // */
    //@Delete("delete from r_order where orderid = #{orderid}")
    //int deleteOrder(Order order);

    /**
     * 支付前添加地址
     * @param map
     * @return
     */
    @Update("update r_order set addressId = #{addressId} where userid = #{userid} and orderState = 1")
    int payment(Map<String,Object> map);
    /**
     * 沙箱环境信息
     * @param map
     * @return
     */
    @Select("select * from r_order where userid = #{userid} and orderid = #{orderid}")
    Order queryAlipayOrder(Map<String,Object> map);
    /**
     * 显示订单按时间排序
     * @param userid
     * @return
     */
    @Select("select * from r_order where userid = #{userid} order by orderdate DESC")
    List<Order> queryShopOrder(@Param("userid") Integer userid);
    /**
     * 修改订单状态
     * @param map
     * @return
     */
    @Update("update r_order set orderState = #{orderState} where orderid = #{orderid}")
    int updateOrderState(Map<String,Object> map);

    /**
     * 定时任务:过期订单
     * @return
     */
    @Update("update r_order set orderState=0 where orderState=1")
    int deleteOrderBeOverdue();

    /**
     * 订单信息
     * @param stateid
     * @return
     */
    List<OrderAddress> queryOrderAddress(@Param("stateid") Integer stateid);

    /**
     * 订单状态
     * @return
     */
    @Select("select * from r_order_state")
    List<OrderState> queryOrderStateAll();

}
